/**
 * @Project Name:hoofungson-elk-log
 * @Package Name:cn.hoofungson.framework.elk.log.util
 * @Since JDK 1.8
 */

package cn.hoofungson.framework.elk.log.util;

/**
 * @Description: StringBuilderUtils
 * @Author 胡松 hoofungson@163.com
 * @Date 2019-08-30 14:27
 * @Version V1.0
 */
public class StringBufferUtils {

    /**
     * 最小字符长度：0
     **/
    private static final Integer DEFAULT_MIN_LENGTH = 0;

    /**
     * 前缀匹配Index：0
     **/
    private static final Integer DEFAULT_PREFIX_INDEX = 0;

    private StringBufferUtils() {
    }

    /**
     * 是否为Null
     *
     * @param stringBuffer
     * @return
     **/
    public static Boolean isNull(StringBuffer stringBuffer) {
        return null == stringBuffer ? true : false;
    }

    /**
     * 是否不为Null
     **/
    public static Boolean isNotNull(StringBuffer stringBuffer) {
        return null != stringBuffer ? true : false;
    }

    /**
     * 是否为空字符串
     *
     * @param stringBuffer
     * @return
     **/
    public static Boolean isBlank(StringBuffer stringBuffer) {
        if (isNull(stringBuffer)) {
            return true;
        }
        if (!(stringBuffer.length() > DEFAULT_MIN_LENGTH)) {
            return true;
        }
        return false;
    }

    /**
     * 是否不为空字符串
     *
     * @param stringBuffer
     * @return
     **/
    public static Boolean isNotBlank(StringBuffer stringBuffer) {
        if (isNotNull(stringBuffer)
                && stringBuffer.length() > DEFAULT_MIN_LENGTH) {
            return true;
        }
        return false;
    }

    /**
     * 是否以指定字符串开头
     *
     * @param stringBuffer
     * @param origin
     * @return
     **/
    public static Boolean isStartWith(StringBuffer stringBuffer, String origin) {
        if (isBlank(stringBuffer)) {
            return false;
        }
        if (stringBuffer.indexOf(origin) == DEFAULT_PREFIX_INDEX) {
            return true;
        }
        return false;
    }

    /**
     * 是否以指定字符串开头
     *
     * @param stringBuffer
     * @param origin
     * @return
     **/
    public static Boolean isEndWith(StringBuffer stringBuffer, String origin) {
        if (isBlank(stringBuffer)) {
            return false;
        }
        Integer originIndex = stringBuffer.indexOf(origin);
        if (originIndex == DEFAULT_PREFIX_INDEX
                && (stringBuffer.length() - 1 == originIndex)) {
            return true;
        }
        return false;
    }
}
